package com.poseidon.pokers;

import android.app.Activity;
import android.app.Application;
import android.support.v4.app.Fragment;

import com.blankj.utilcode.util.Utils;
import com.facebook.stetho.Stetho;
import com.luojilab.component.componentlib.router.Router;
import com.luojilab.component.componentlib.router.ui.UIRouter;
import com.luojilab.componentservice.GlobalEventManager;
import com.luojilab.componentservice.app.DaggerComponentService;
import com.poseidon.pokers.di.AppComponent;
import com.poseidon.pokers.di.DaggerAppComponent;
import com.then.architecture.InjectorMap;
import com.then.architecture.di.DaggerComponent;
import com.then.architecture.di.DaggerDelegate;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;

import javax.inject.Inject;

import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import dagger.android.support.HasSupportFragmentInjector;
import timber.log.Timber;

/**
 * Created by 42524 on 2018/1/12.
 */

public class MainApp extends Application implements HasActivityInjector, HasSupportFragmentInjector {

    @Inject
    DispatchingAndroidInjector<Activity> mActivityInjector;

    @Inject
    DispatchingAndroidInjector<Fragment> mFragmentInjector;

    @Inject
    InjectorMap injectorMap;

    @Inject
    GlobalEventManager globalEventManager;

    private DaggerDelegate mDaggerDelegate;

    private AppComponent mAppComponent;

    private String wxAppId = "wxc7403e0dff96ed1a";

    private String umAppKey = "F9B0D8C4629D737EB3144A98D58D0C0F";


    @Override
    public void onCreate() {
        super.onCreate();
        Utils.init(this);
        Stetho.initializeWithDefaults(this);
        PlatformConfig.setWeixin(wxAppId, umAppKey);

        Config.DEBUG = true;
        //Library 的依赖注入（顶级）
        mDaggerDelegate = new DaggerDelegate(this);
        mDaggerDelegate.onCreate();

        //注入主 Module 中（该 Module 全局）
        mAppComponent = DaggerAppComponent.builder()
                .daggerComponent(getDaggerComponent())
                .build();
        mAppComponent.inject(this);
        injectorMap.putActivityInjector(BuildConfig.APPLICATION_ID, this);
        UIRouter.getInstance().registerUI("main");
        Router.getInstance().addService(DaggerComponentService.class.getSimpleName(), getDaggerComponent());
    }

    public DaggerComponent getDaggerComponent() {
        return mDaggerDelegate.getComponent();
    }

    public AppComponent getAppComponent() {
        return mAppComponent;
    }

    @Override
    public AndroidInjector<Activity> activityInjector() {
        return mActivityInjector;
    }

    @Override
    public AndroidInjector<Fragment> supportFragmentInjector() {
        return this.mFragmentInjector;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }


}
